local skel = fk.CreateSkill {
  name = "lb__shuyan",
  tags = { Skill.Hidden },
}

skel.HiddenGeneral = "lb__sanyueqi"

local U = require "packages.utility.utility"
local LB_U = require "packages.lb_kill_utility.utility"

Fk:loadTranslationTable {
  ["lb__shuyan"] = "殊颜",
  [":lb__shuyan"] = "<b>隐匿技</b>，你以“三月七”隐匿。其回合开始或受到伤害后，你登场并摸一张牌，然后你可以对伤害来源使用一张牌。",

  ["#lb__shuyan"] = "殊颜：你可以对 %dest 使用一张牌",

  ["$lb__shuyan1"] = "也算一段不错的回忆。",
  ["$lb__shuyan2"] = "好啦，不要再胡闹了。",
}

skel:addEffect(U.GeneralAppeared, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.reason == skel.name
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, skel.name)
    if player:isAlive() and player:getMark(skel.name) ~= 0 then
      local from = room:getPlayerById(player:getMark(skel.name))
      room:setPlayerMark(player, skel.name, 0)
      if from and from:isAlive() then
        local id = from.id
        room:askToPlayCard(player, {
          pattern = ".",
          skill_name = skel.name,
          extra_data = { exclusive_targets = { id }, bypass_times = true, extraUse = true },
          cancelable = true,
          prompt = "#lb__shuyan::" .. id,
        })
      end
    end
  end,
  can_refresh = function(self, event, target, player, data)
    return player:getMark("HiddenGeneral") == skel.name and target == player and player:isAlive()
  end,
  on_refresh = function(self, event, target, player, data)
    for _, name in ipairs(Fk.generals[skel.HiddenGeneral]:getSkillNameList(true)) do
      player.room:handleAddLoseSkills(player, "-" .. name, nil, false, true)
    end
  end,
})

local shuyan_spec = {
  global = true,
  can_refresh = function(self, event, target, player, data)
    return player:getMark("HiddenGeneral") == skel.name and target == player and player:isAlive()
  end,
  on_refresh = function(self, event, target, player, data)
    if data.from then
      player.room:setPlayerMark(player, skel.name, data.from.id)
    end
    --U.GeneralAppear(player, skel.name)
    LB_U.GeneralAppear(player, skel.name)
  end,
}

skel:addEffect(fk.Damaged, shuyan_spec)
skel:addEffect(fk.TurnStart, shuyan_spec)


return skel
